package com.vnp.cooking;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.vnp.cooking.adapter.TaoMonAnChonKieuAdapter;
import com.vnp.cooking.bean.ObjCookpad;
import com.vnp.cooking.bean.ObjSlidingMenu;

public class TaoMonAnChonLoaiMonActivity extends Activity implements
		OnClickListener {
	ObjSlidingMenu[] objSlidingMenus;
	ListView lsView;
	TaoMonAnChonKieuAdapter adapter;
	ImageButton btnBack, btnNextStep;
	// backgroundd mon an
	ImageView imgMonan;

	// object tao mon an
	ObjCookpad objCookpad = new ObjCookpad();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_tao_mon_an_chon_loai_mon);
		btnBack = (ImageButton) findViewById(R.id.btn_back);
		btnNextStep = (ImageButton) findViewById(R.id.btn_next_step);
		imgMonan = (ImageView) findViewById(R.id.img_mon_an);
		lsView = (ListView) findViewById(R.id.ls_type_monan);
		
		objCookpad = getIntent().getParcelableExtra("objCookpad");
		
		// bimatp factory
        BitmapFactory.Options options = new BitmapFactory.Options();

        // downsizing image as it throws OutOfMemory Exception for larger
        // images
        options.inSampleSize = 8;
		try {
			Uri uri = Uri.parse(objCookpad.getUrlImageCookpad());
			Bitmap bitmap = BitmapFactory.decodeFile(uri.getPath(), options);
			imgMonan.setImageBitmap(bitmap);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		// Ten mon an
		Log.i("Test", objCookpad.getNameCookpad());
		
		adapter = new TaoMonAnChonKieuAdapter(this, createData());
		lsView.setAdapter(adapter);
		
		// set onclick cho chung
		btnBack.setOnClickListener(this);
		btnNextStep.setOnClickListener(this);
		lsView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View view, int position,
					long id) {
				
			}
		});
	}

	public ArrayList<ObjSlidingMenu> createData() {
		ArrayList<ObjSlidingMenu> items = new ArrayList<ObjSlidingMenu>();
		items.add(new ObjSlidingMenu(R.drawable.ic_sld001, "Nguồn gốc món ăn"));
		items.add(new ObjSlidingMenu(R.drawable.ic_sld002, "Bữa ăn"));
		items.add(new ObjSlidingMenu(R.drawable.ic_sld003, "Dịp nấu"));
		return items;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_back:
			finish();
			break;

		case R.id.btn_next_step:
			Intent t = new Intent(TaoMonAnChonLoaiMonActivity.this,
					TaoMonAnCamNghiActivity.class);
			t.putExtra("objCookpad", objCookpad);
			startActivity(t);
			break;
		}

	}

}
